package com.zjj.lbw.guava.joiner;

import com.google.common.base.Splitter;
import org.junit.Test;

import java.util.List;

/**
 * @author zhanglei.zjj
 * @description guava字符串处理之Splitter
 * @date 2023/7/16 15:51
 */
public class TestGuavaSplitter {

    /**
     * splitter on 拆分
     */
    @Test
    public void splitterListTest() {
        String test = "34344,34,34,哈哈";
        List<String> lists = Splitter.on(",").splitToList(test);
        System.out.println(lists);
    }

    /**
     * splitter trimResults 拆分去除前后空格
     */
    @Test
    public void trimResultListTest() {
        String test = " 34344,34,34,哈哈 ";
        List<String> lists =
                Splitter.on(",").trimResults().splitToList(test);
        System.out.println(lists);
    }

    /**
     * splitter omitEmptyStrings 去除拆分出来空的字符串
     */
    @Test
    public void omitEmptyStringsTest() {
        String test = " 3434,434,34,,哈哈 ";
        List<String> lists =
                Splitter.on(",").omitEmptyStrings().splitToList(test);
        System.out.println(lists);
    }

    /**
     * splitter fixedLength(int lenght) 把字符串按固定⻓度分割
     */
    @Test
    public void fixedLengthTest() {
        String test = "343443434哈哈";
        List<String> lists = Splitter.fixedLength(3).splitToList(test);
        System.out.println(lists);
    }

}

